﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using DHJ.Cost.Configuration;
using DHJ.Cost.Web;

namespace DHJ.Cost.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class CostDbContextFactory : IDesignTimeDbContextFactory<CostDbContext>
    {
        public CostDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<CostDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder(), addUserSecrets: true);

            CostDbContextConfigurer.Configure(builder, configuration.GetConnectionString(CostConsts.ConnectionStringName));

            return new CostDbContext(builder.Options);
        }
    }
}